home *** CD-ROM | disk | FTP | other *** search
- unit Ddcomp;
-
- interface
- uses
- SysUtils, Classes, Forms, Controls,
- Dialogs, DB, DBTables, inifiles, grids;
- const
- FieldTypeStr : array[ftunknown..ftgraphic] of string[8] =
- ('Unknown', 'String', 'Smallint', 'Integer', 'Word',
- 'Boolean', 'Float', 'Currency', 'BCD', 'Date', 'Time',
- 'DateTime', 'Bytes', 'VarBytes', 'Blob', 'Memo', 'Graphic');
- FieldTypeLtr : array[ftunknown..ftgraphic] of string[1] =
- ('U', 'S', 'I', 'N', 'W',
- 'L', 'F', 'C', 'B', 'D', 'T',
- 'A', 'Y', 'V', 'O', 'M', 'G');
-
- type
- DDValidationtype = (IsValidDD, DoesNotExist, ExistbutnotDD, NewDD, EmptyString );
-
- TDDCtrl = class(TComponent)
- private
- DictDB: TDatabase;
- DictTable: TTable;
- DictQuery: TQuery;
- DictSource: TDataSource;
- FiniFile : TiniFile;
- FCtrlDictName : Tfilename; {fully qualified name}
- FDictStatus : DDValidationType;
- FDBSGGood : boolean;
- FTableList : tStrings;
- FDBSG : Tstringgrid; {active part of dictionary}
- FUpdated : Tdatetime; {info on current dictionary}
- FDictsize : longint;
- FnumRecords,
- Fnumtables,
- FnumFields : integer;
- procedure ReadIniFile;
- function getDictPath : tfilename;
- procedure setDictPath( tmpstr : tfilename);
- function getDictTable : tfilename;
- procedure setDictTable (tmpstr : tfilename);
- function setUpCommon(var TableToDefine : ttable; const cur_row : integer): boolean;
- function SetUpString(var TableToDefine : ttable; const cur_row : integer): boolean;
- function SetUpBoolean(var TableToDefine : ttable; const cur_row : integer): boolean;
- function doNumbers(const whichtype : char; var TableToDefine : ttable; const cur_row : integer): boolean;
- function setAfterFieldDef(var tableToDefine : Ttable; const cur_row : integer): boolean;
- function setUpBeforeCommon(var TableToDefine : ttable; const cur_row : integer): boolean;
- function SetUpBeforeString(var TableToDefine : ttable; const cur_row : integer): boolean;
- function SetUpBeforeBoolean(var TableToDefine : ttable; const cur_row : integer): boolean;
- function doBeforeNumbers(const whichtype : char; var TableToDefine : ttable; const cur_row : integer): boolean;
- function setBeforeFieldDef(var tableToDefine : Ttable; const cur_row : integer): boolean;
-
- protected
- function OpenDD(const pathname, tablename : string): boolean;
- function CheckOutDD(const Fulltablename : string): DDValidationtype;
- function BuildDictCtrlGrid(SQLparams : string): boolean;
- function ValidateDictCtrlGrid: boolean;
- function tableInDBSG(const whichtable : string): boolean;
- public
- Constructor create(Aowner : Tcomponent); override;
- function SetUpTableBeforeOpen(var TableToSetUp : ttable; const whichTable : string): boolean;
- function SetUpTableAfterOpen(var TableToSetUp : ttable; const whichTable : string): boolean;
-
- published
- property DictStatus: DDValidationType read FDictStatus;
- property FullDDName : tFilename read FCtrlDictName write FCtrlDictName;
- property DictPathName: Tfilename read getDictPath;
- property DictTableName: Tfilename read getDictTable;
- property LastUpdate: tDateTime read Fupdated;
- property DictSize: longint read FDictSize;
- property NumRecords: integer read FNumRecords;
- property numtables: integer read fNumtables;
- property numfields: integer read fNumFields;
- property DBSGExists : boolean read FDBSGGood;
- end;
-
-
- procedure Register;
-
- var
-
- DDctrlIsInit : boolean;
-
-
- implementation
-
-
- uses utils
- {$ifdef buggy}, runinfo {$endif};
- const
- {indexes into DBSG columns}
- ddTablename = 0; {string 20}
- ddTabletype = 1; {string 20}
- ddFieldname = 2; {string[20];}
- ddTagfld = 3; {string 20 tfield.tag}
- ddScrprompt = 4; {string[40]; {tfield.DisplayName}
- ddScrformat = 5; {string[80]; {tfield.DisplayText -- an editmask}
- ddGrdprompt = 6; {string[10];}
- ddGrdwidth = 7; {smallint {tfield.DisplayWidth}
- ddFldtype = 8; {string[1]; {FieldTypeLtr}
- ddFldlen = 9; {smallint {tfield.size}
- ddFlddec = 10; {smallint}
- ddFldidx = 11; {boolean;}
- ddIdxexp = 12; {string;}
- ddTab_order = 13; {integer;}
- ddRequired = 14; {boolean; {tfield.required}
- ddDefault = 15; {string[80];}
- ddEditmask = 16; {string[80]; {tfield.editMask}
- ddMinval = 17; {ftfloat tfield.minvalue}
- ddMaxval = 18; {ftfloat tfield.maxvalue}
- ddVallist = 19; {ftmemo list of valid strings}
- { define documentation only
- validvalue documentation only
- notes documentation only}
- ddHintTxt = 20; {string 120}
- ddHelpid = 21; {longint;}
- {help, memo only used if helpid not null or 0}
- ddHasLink = 22; {boolean;}
- ddSrclinktbl = 23; {string[20];}
- ddSrclinkfld = 24; {string[20];}
- ddIsCalc = 25; {boolean;}
- ddFormula = 26; {memo only used if iscalc true}
-
- Procedure TDDCtrl.ReadIniFile;
- begin
- FIniFile := TiniFile.Create(appname+'.ini');
- FCtrlDictName := FiniFile.ReadString('CtrlDict', 'current', appname+'.dbf');
- FiniFile.free;
- end;
-
- function TDDCtrl.getDictPath : tfilename;
- begin
- result := extractFilePath(FCtrlDictName);
- end;
- procedure TDDCtrl.setDictPath( tmpstr : tfilename);
- begin
- FCtrlDictName := tmpstr;
- end;
- function TDDCtrl.getDictTable : tfilename;
- begin
- result := copy(extractFileName(FCtrlDictName), 1, pos('.',extractFileName(FCtrlDictName))-1);
- end;
- procedure TDDCtrl.setDictTable (tmpstr : tfilename);
- begin
- end;
-
- constructor TDDCtrl.create(Aowner : Tcomponent);
- begin
- inherited create(Aowner);
- {$ifdef buggy}
- runinfoform.updateinfo( 'Start ddctrl');
- {$endif}
- readIniFile;
- DictDB := Tdatabase.Create(Aowner);
- DictTable := TTable.create(Aowner);
- DictQuery := TQuery.create(Aowner);
- DictSource := Tdatasource.create(aOwner);
- DictDB.Databasename := 'DataDictCtrlFormDB';
- if CheckOutDD(FCtrlDictName) = IsValidDD
- then begin
-
- messagedlg('foundit', mtinformation, [mbOK],0);
-
- {first check it out}
- {pull data into stringgrid?
- or set up a permanent link/ query table
- with data to modify current app
- }
- end
- else begin
- messagedlg('not IsValidDD', mtinformation, [mbOK],0);
- {some kind of message about no dictionary
- present?
- }
- end;
- {$ifdef buggy}
- runinfoform.updateinfo('before ddctrl done');
- {$endif}
- DictSource.free;
- DictQuery.free;
- DictTable.free;
- DictDB.free;
- {$ifdef buggy}
- runinfoform.updateinfo('end create ddctrl');
- {$endif}
- end;
-
-
- function TDDCtrl.openDD(const pathname, tablename : string): boolean;
- begin
- try
- DictDB.close;
- DictDB.Params.clear;
- DictDB.Params.Add('PATH='+PathName);
- DictDB.DriverName := 'STANDARD';
- DictDB.open;
- DictTable.DatabaseName:= DictDB.databasename;
- DictTable.TableType := ttDbase;
- DictTable.tablename := TableName;
- DictTable.Active:= True;
- DictSource.DataSet:= DictTable;
- DictQuery.databaseName := DictDB.databasename;
- DictQuery.dataSource := DictSource;
- DictQuery.close;
- DictQuery.sql.clear;
- DictQuery.params.clear;
- result := true;
- except
- on EdataBaseError do begin
- screen.cursor := crDefault;
- MessageDlg('Could not open '+pathname + ' '+tablename, mtInformation, [mbOK], 0);
- result := false;
- end;
- end; {of exceptions}
- end;
-
- function TDDCtrl.CheckOutDD(const Fulltablename : string): DDValidationtype;
- var
- tablefound : boolean;
- sqlstr,
- thistable : string;
- tablenum : integer;
- FileInfo : TsearchRec;
- tableField : tField;
-
- begin
- result := isValidDD;
- fnumtables := 0; fnumFields := 0; fDictsize := 0; fNumRecords := 0;
- FTableList := tstringlist.create;
- if fileExists(fulltablename)
- then begin
- FindFirst(fulltablename, faAnyfile, fileinfo);
- FUpdated := fileDateToDateTime(Fileinfo.time);
- fDictSize := FileInfo.size;
- {not total size, should also get size of .dbt }
- end
- else begin
- result := DoesNotExist;
- exit;
- end;
- if openDD(DictPathName, DictTableName)
- then begin
- fnumrecords := DictTable.RecordCount;
- sqlstr := 'SELECT * FROM '+DictTableName;
- Dictquery.sql.add(sqlstr);
- Dictquery.prepare;
- Dictquery.open;
- Dictquery.first;
- { get tablenames in data dictionary, stick in M_tableList lines}
- if DictQuery.findfield('TABLE_NAME') = nil
- then begin
- result := ExistButNotDD;
- exit;
- end;
- ftableList.add(DictQuery.findfield('TABLE_NAME').text); {get first one}
- inc(fnumfields);
- DictQuery.next;
- while not DictQuery.eof do begin
- tablefound := false;
- thistable := DictQuery.findfield('TABLE_NAME').text;
- inc(fnumFields);
- for tablenum := 0 to ftablelist.count - 1 do
- if ftableList.strings[tablenum] = thistable
- then begin
- tablefound := true;
- break;
- end;
- {done looking for thistable}
- if not tablefound
- then ftablelist.add(thistable);
- DictQuery.next;
- end; {while searching for table names}
- DictQuery.close;
- If not BuildDictCtrlGrid(sqlstr)
- then result := ExistButNotDD;
- end
- else begin
- result := ExistbutnotDD;
- end;
- end;
-
- function TDDCtrl.BuildDictCtrlGrid(sqlparams : string): boolean;
- var
- tmpstr : string;
- tablefound : boolean;
- tablenum,
- cur_row : integer;
- begin
- try
- DictQuery.close;
- DictQuery.sql.clear;
- DictQuery.params.clear;
- tmpstr := sqlparams +' where TABLE_NAME = :tableid';
- DictQuery.sql.add(tmpstr);
- DictQuery.prepare;
- cur_row := 0;
- fdbsg := TstringGrid.create(self);
- fdbsg.rowcount := DictTable.recordCount;
- fdbsg.colcount := DictTable.fieldCount;
- for tablenum := 0 to FTableList.count - 1 do begin
- DictQuery.close;
- DictQuery.ParamByName('tableid').asString := FtableList.strings[tablenum];
- DictQuery.open;
- DictQuery.first;
- while not DictQuery.eof do begin
- fDBSG.cells[ddtablename,cur_row] := DictQuery.findfield('TABLE_NAME').text;
- fDBSG.cells[ddtabletype,cur_row] := DictQuery.findfield('TABLE_tYPE').text;
- fDBSG.cells[ddfieldname,cur_row] := DictQuery.findfield('FIELD_NAME').text;
- fDBSG.cells[ddtagfld,cur_row] := DictQuery.findfield('TAG').text;
- fDBSG.cells[ddscrprompt,cur_row] := DictQuery.findfield('SCR_PROMPT').text;
- fDBSG.cells[ddscrformat,cur_row] := DictQuery.findfield('SCR_FMT').text;
- fDBSG.cells[ddgrdprompt,cur_row] := DictQuery.findfield('GRD_PROMPT').text;
- fDBSG.cells[ddgrdwidth,cur_row] := DictQuery.findfield('GRD_WIDTH').asString;
- fDBSG.cells[ddfldtype ,cur_row] := DictQuery.findfield('FIELD_TYPE').text;
- fDBSG.cells[ddfldlen ,cur_row] := DictQuery.findfield('FIELD_LEN').asString;
- fDBSG.cells[ddflddec ,cur_row] := DictQuery.findfield('FIELD_DEC').asString;
- fDBSG.cells[ddfldidx ,cur_row] := DictQuery.findfield('FIELD_IDX').asString;
- fDBSG.cells[ddidxexp ,cur_row] := DictQuery.findfield('IDX_EXPRES').text; {first line only}
- fDBSG.cells[ddtab_order ,cur_row] := DictQuery.findfield('TAB_ORDER').asString;
- fDBSG.cells[ddrequired ,cur_row] := DictQuery.findfield('REQUIRED').asString;
- fDBSG.cells[dddefault ,cur_row] := DictQuery.findfield('DEFAULT').text;
- fDBSG.cells[ddeditmask ,cur_row] := DictQuery.findfield('EDITMASK').text;
- fDBSG.cells[ddminval ,cur_row] := DictQuery.findfield('MINVAL').asString;
- fDBSG.cells[ddmaxval ,cur_row] := DictQuery.findfield('MAXVAL').asString;
- fDBSG.cells[ddvallist ,cur_row] := DictQuery.findfield('VALLIST').text; {first line only}
- fDBSG.cells[ddhinttxt ,cur_row] := DictQuery.findfield('HINT').text;
- fDBSG.cells[ddhelpid ,cur_row] := DictQuery.findfield('HELPID').asSTring;
- fDBSG.cells[ddhaslink ,cur_row] := DictQuery.findfield('HASLINK').asSTring;
- fDBSG.cells[ddsrclinktbl ,cur_row] := DictQuery.findfield('SRCLINKTBL').text;
- fDBSG.cells[ddsrclinkfld ,cur_row] := DictQuery.findfield('SRCLINKFLD').text;
- fDBSG.cells[ddiscalc ,cur_row] := DictQuery.findfield('IS_CALC').asString;
- fDBSG.cells[ddformula ,cur_row] := DictQuery.findfield('FORMULA').text;
- inc(cur_row);
- DictQuery.next;
- end;
- end;
- result := true;
- except
- on EdataBaseError do begin
- screen.cursor := crDefault;
- MessageDlg('Problem reading fields in from dictionary', mtInformation, [mbOK], 0);
- result := False;
- end;
- end; {of exceptions}
- if result
- then FDBSGgood := validateDictCtrlGrid
- else FDBSGgood := false;
- end;
-
- function TDDctrl.ValidateDictCtrlGrid: boolean;
- var cur_row : integer;
- thisFieldType : string[1];
- found : boolean;
- thisfield : ftString..ftGraphic;
-
- procedure nogood(const messg : string; const row_num : integer);
- begin
- messagedlg(messg+' at row '+intToStr(row_num), mtInformation, [mbOK], 0);
- result := false;
- end;
-
- begin
- { if Not FDBSGgood
- then begin
- Result := false;
- MessageDlg('DB Control structure does not exist', mtinformation, [mbOK],0);
- end
- else begin with fDBSG do begin}
- with fDBSG do begin
- result := true;
- for cur_row := 0 to rowcount -1 do begin
- if fDBSG.cells[ddtablename,cur_row] = ''
- then nogood('Blank Table name',cur_row);
- if fDBSG.cells[ddfieldname,cur_row] = ''
- then nogood('Field name blank',cur_row);
- if fDBSG.cells[ddfldtype ,cur_row] = ''
- then nogood('Field type blank',cur_row)
- else begin
- found := false;
- ThisFieldType := fDBSG.cells[ddfldtype, cur_row];
- for thisfield := ftString to ftgraphic do
- if FieldTypeLtr[thisfield] = thisfieldtype
- then begin found := true; break; end;
- if not found
- then nogood('Invalid field type: '+ThisFieldType, cur_row);
- end;
- end; {for cur_row to rowcount}
- end; {with fDBSG}
- end;
-
- function TDDCtrl.tableInDBSG(const whichtable : string): boolean;
- var i : integer;
- begin
- result := false;
- with fTableList do
- for i := 0 to Ftablelist.count -1 do
- if whichtable = Ftablelist.strings[i]
- then begin result := true; break; end;
- end;
-
-
-
-
-
- function TDDctrl.SetUpCommon(var TableToDefine : ttable; const cur_row : integer): boolean;
- var whichfield : string;
- begin with fDBSG do begin
- whichfield := cells[ddfieldname, cur_row];
- if cells[ddtagfld, cur_row] <> ''
- then TableToDefine.findField(whichField).tag := StrToint(cells[ddtagfld, cur_row]);
- {if cells[ddscrprompt,cur_row] <> ''
- then TableToDefine.findField(whichField). := cells[ddscrprompt, cur_row];}
- if cells[ddgrdprompt,cur_row] <> ''
- then TableToDefine.findfield(whichField).DisplayLabel := cells[ddgrdprompt, cur_row];
- if cells[ddgrdwidth,cur_row] <> ''
- then TableToDefine.findfield(whichField).DisplayWidth := StrToInt(cells[ddgrdwidth, cur_row]);
- if cells[ddEditMask, cur_row] <> ''
- then TableToDefine.findField(whichfield).EditMask
- := cells[ddEditMask, cur_row];
- if cells[ddrequired ,cur_row] = 'true'
- then TableToDefine.findfield(whichfield).required := true
- else TableToDefine.findField(whichField).required := false;
- {
- fDBSG.cells[dddefaultis ,cur_row] := qry.findfield('DEFAULT').text;
- fDBSG.cells[ddeditmaskis ,cur_row] := qry.findfield('EDITMASK').text;
- fDBSG.cells[ddminval ,cur_row] := qry.findfield('MINVAL').asString;
- fDBSG.cells[ddmaxval ,cur_row] := qry.findfield('MAXVAL').asString;
- fDBSG.cells[ddvallist ,cur_row] := qry.findfield('VALLIST').text;
- fDBSG.cells[ddhinttxt ,cur_row] := qry.findfield('HINT').text;
- fDBSG.cells[ddhelpid ,cur_row] := qry.findfield('HELPID').asSTring;
- fDBSG.cells[ddhaslink ,cur_row] := qry.findfield('HASLINK').asSTring;
- fDBSG.cells[ddsrclinktbl ,cur_row] := qry.findfield('SRCLINKTBL').text;
- fDBSG.cells[ddsrclinkfld ,cur_row] := qry.findfield('SRCLINKFLD').text;
- fDBSG.cells[ddiscalc ,cur_row] := qry.findfield('IS_CALC').asString;
- fDBSG.cells[ddformula ,cur_row] := qry.findfield('FORMULA').text;
- tfield }
-
-
- end;
- end;
-
- function TDDCtrl.SetUpString(var TableToDefine : ttable; const cur_row : integer): boolean;
- var whichfield : string;
- begin with fDBSG do begin
- whichfield := cells[ddfieldname, cur_row];
- if cells[ddscrFormat,cur_row] <> ''
- then TableToDefine.findField(whichfield).EditMask
- := cells[ddscrFormat,cur_row];
- if cells[ddEditMask, cur_row] <> ''
- then TableToDefine.findField(whichfield).EditMask
- := cells[ddEditMask, cur_row];
- (** apparently cannot change size
- well, suppose that makes sense. So field_len only to be
- used for strings when creating tables, not after they are built
-
- if cells[ddfldlen, cur_row] <> ''
- then begin
- { TableToDefine.active := false;}
- TableToDefine.findField(whichField).size := StrToint(cells[ddfldlen, cur_row]);
- {tableToDefine.active := true;}
- end;
- **)
- end;
- end;
-
- function TDDCtrl.SetUpBoolean(var TableToDefine : ttable; const cur_row : integer): boolean;
- var whichfield : string;
- begin with fDBSG do begin
- whichfield := cells[ddfieldname, cur_row];
- if cells[ddValList, cur_row] <> ''
- then TBooleanField(TableToDefine.findField(whichfield)).DisplayValues
- := cells[ddValList, cur_row];
- end;
- end;
-
- {required
- fDBSG.cells[ddtablename,cur_row] := qry.findfield('TABLE_NAME').text;
- fDBSG.cells[ddfieldname,cur_row] := qry.findfield('FIELD_NAME').text;
- fDBSG.cells[ddtag,cur_row] := qry.findfield('TAG').text;
- fDBSG.cells[ddscrprompt,cur_row] := qry.findfield('SCR_PROMPT').text;
- fDBSG.cells[ddscrformat,cur_row] := qry.findfield('SCR_FMT').text;
- fDBSG.cells[ddgrdprompt,cur_row] := qry.findfield('GRD_PROMPT').text;
- fDBSG.cells[ddgrdwidth,cur_row] := qry.findfield('GRD_WIDTH').asString;
- fDBSG.cells[ddfldtype ,cur_row] := qry.findfield('FIELD_TYPE').text;
- fDBSG.cells[ddfldlen ,cur_row] := qry.findfield('FIELD_LEN').asString;
- fDBSG.cells[ddflddec ,cur_row] := qry.findfield('FIELD_DEC').asString;
- fDBSG.cells[ddfldidx ,cur_row] := qry.findfield('FIELD_IDX').asString;
- fDBSG.cells[ddidxexp ,cur_row] := qry.findfield('IDX_EXPRES').text;
- fDBSG.cells[ddtab_order ,cur_row] := qry.findfield('TAB_ORDER').asString;
- fDBSG.cells[ddisrequired ,cur_row] := qry.findfield('REQUIRED').asString;
- fDBSG.cells[dddefaultis ,cur_row] := qry.findfield('DEFAULT').text;
- fDBSG.cells[ddeditmaskis ,cur_row] := qry.findfield('EDITMASK').text;
- fDBSG.cells[ddminval ,cur_row] := qry.findfield('MINVAL').asString;
- fDBSG.cells[ddmaxval ,cur_row] := qry.findfield('MAXVAL').asString;
- fDBSG.cells[ddvallist ,cur_row] := qry.findfield('VALLIST').text;
- fDBSG.cells[ddhinttxt ,cur_row] := qry.findfield('HINT').text;
- fDBSG.cells[ddhelpid ,cur_row] := qry.findfield('HELPID').asSTring;
- fDBSG.cells[ddhaslink ,cur_row] := qry.findfield('HASLINK').asSTring;
- fDBSG.cells[ddsrclinktbl ,cur_row] := qry.findfield('SRCLINKTBL').text;
- fDBSG.cells[ddsrclinkfld ,cur_row] := qry.findfield('SRCLINKFLD').text;
- fDBSG.cells[ddiscalc ,cur_row] := qry.findfield('IS_CALC').asString;
- fDBSG.cells[ddformula ,cur_row] := qry.findfield('FORMULA').text;
- }
-
-
-
-
-
- function SetUpDate(var TableToDefine : ttable; const cur_row : integer): boolean;
- begin
- end;
-
- function SetUpDateTime(var TableToDefine : ttable; const cur_row : integer): boolean;
- begin
- end;
-
- function SetUpTime(var TableToDefine : ttable; const cur_row : integer): boolean;
- begin
- end;
-
- function SetUpBytes(var TableToDefine : ttable; const cur_row : integer): boolean;
- begin
- end;
-
- function SetUpVarBytes(var TableToDefine : ttable; const cur_row : integer): boolean;
- begin
- end;
-
- function SetUpBlob(var TableToDefine : ttable; const cur_row : integer): boolean;
- begin
- end;
-
- function SetUpMemo(var TableToDefine : ttable; const cur_row : integer): boolean;
- begin
- end;
-
- function SetUpGraphic(var TableToDefine : ttable; const cur_row : integer): boolean;
- begin
- end;
-
- function TDDCtrl.doNumbers(const whichtype : char; var TableToDefine : ttable; const cur_row : integer): boolean;
- var whichfield : string;
- begin with fDBSG do begin
- whichfield := cells[ddfieldname, cur_row];
- if (cells[ddminval, cur_row] = '') and (cells[ddmaxval, cur_row] = '')
- then begin
- result := true;
- exit;
- end;
- case whichtype of
- 'I': begin {ftSmallint}
- if cells[ddminval, cur_row] <> ''
- then TSmallIntField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TSmallIntField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- end;
- 'N': begin {ftInteger}
- if cells[ddminval, cur_row] <> ''
- then TIntegerField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TIntegerField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- end;
-
- 'W' : begin {ftWord}
- if cells[ddminval, cur_row] <> ''
- then TWordField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TWordField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- end;
- 'F' : begin {ftFloat}
- if cells[ddminval, cur_row] <> ''
- then TFloatField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TFloatField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- if cells[ddfldlen, cur_row] <> ''
- then TFloatField(TableToDefine.findField(whichfield)).Precision
- := StrToInt(cells[ddfldlen, cur_row]);
- end;
- 'C' : begin {ftCurrency}
- if cells[ddminval, cur_row] <> ''
- then TCurrencyField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TCurrencyField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- if cells[ddfldlen, cur_row] <> ''
- then TCurrencyField(TableToDefine.findField(whichfield)).Precision
- := StrToInt(cells[ddfldlen, cur_row]);
- end;
- 'B' : begin {ftBCD}
- if cells[ddminval, cur_row] <> ''
- then TBCDField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TBCDField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- if cells[ddfldlen, cur_row] <> ''
- then TBCDField(TableToDefine.findField(whichfield)).Precision
- := StrToInt(cells[ddfldlen, cur_row]);
- end;
- end; {Case }
- end; {with fDBSG}
- end;
-
-
- function TDDCtrl.setAfterFieldDef(var tableToDefine : Ttable; const cur_row : integer): boolean;
- var temprslt : boolean;
- begin
- result := false;
- temprslt := SetUpCommon(tableToDefine, cur_row);
- case fDBSG.cells[ddfldtype,cur_row][1] of
- 'S' : {ftString} Result := SetUpString(tableToDefine, cur_row);
- 'I', {ftSmallint}
- 'N', {ftInteger}
- 'W' : {ftWord} Result := DoNumbers(fDBSG.cells[ddfldtype, cur_row][1], tableToDefine, cur_row);
- 'L' : {ftBoolean} Result := SeTUpBoolean(tableToDefine, cur_row);
- 'F', {ftFloat}
- 'C', {ftCurrency}
- 'B' : {ftBCD} Result := DoNumbers(fDBSG.cells[ddfldtype, cur_row][1], tableToDefine, cur_row);
- 'D' : {ftDate} Result := SetUpDate(tableToDefine, cur_row);
- 'T' : {ftTime} Result := SetUpTime(tableToDefine, cur_row);
- 'A' : {ftDateTime} Result := SetUpDateTime(tableToDefine, cur_row);
- 'Y' : {ftBytes} Result := SetUpBytes(tableToDefine, cur_row);
- 'V' : {ftVarBytes} Result := SetUpVarBytes(tableToDefine, cur_row);
- 'O' : {ftBlob} Result := SetUpBlob(tableToDefine, cur_row);
- 'M' : {ftMemo} Result := SetUpMemo(tableToDefine, cur_row);
- 'G' : {ftGraphic} Result := SetUpGraphic(tableToDefine, cur_row);
- end; {Case & for}
- result := result and temprslt;
- end;
-
-
- function TDDCtrl.SetUpTableAfterOpen(var TableToSetUp : ttable; const whichTable : string): boolean;
- var grid_row,
- num_ok,
- num_bad : integer;
- foundit : boolean;
- begin
- result := false;
- num_ok := 0; num_bad := 0;
- if not tableInDBSG(whichtable)
- then exit;
- with fDBSG do begin
- for grid_row := 0 to rowCount -1 do
- if cells[ddTablename, grid_row] = whichtable
- then if setAfterFieldDef( TableToSetUp, grid_row)
- then inc(num_ok)
- else inc(num_bad);
- if num_bad = 0
- then result := true;
-
- (**
- {Is table loaded?}
- for tablenum := 0 to ColCount - 1 do
- if cols[0].strings[tablenum] = whichTable
- then begin foundit := true; start_row := tablenum; break; end;
- {done looking for table name}
- if not foundit
- then exit {returns false}
- else begin
- for tablenum := start_row to ColCount - 1 do
- if cols[0].strings[tablenum] <> whichTable
- then begin end_row := tablenum; break; end;
- end;
- **)
- end; {with fDBSG}
- end;
-
- {============================== before open table set up field defs ================}
-
- function TDDctrl.SetUpBeforeCommon(var TableToDefine : ttable; const cur_row : integer): boolean;
- var whichfield : string;
- begin with fDBSG do begin
- whichfield := cells[ddfieldname, cur_row];
- (**
- if cells[ddtagfld, cur_row] <> ''
- then TableToDefine.findField(whichField).tag := StrToint(cells[ddtagfld, cur_row]);
- {if cells[ddscrprompt,cur_row] <> ''
- then TableToDefine.findField(whichField). := cells[ddscrprompt, cur_row];}
- if cells[ddgrdprompt,cur_row] <> ''
- then TableToDefine.findfield(whichField).DisplayLabel := cells[ddgrdprompt, cur_row];
- if cells[ddgrdwidth,cur_row] <> ''
- then TableToDefine.findfield(whichField).DisplayWidth := StrToInt(cells[ddgrdwidth, cur_row]);
- if cells[ddEditMask, cur_row] <> ''
- then TableToDefine.findField(whichfield).EditMask
- := cells[ddEditMask, cur_row];
- if cells[ddrequired ,cur_row] = 'true'
- then TableToDefine.findfield(whichfield).required := true
- else TableToDefine.findField(whichField).required := false;
- {
- fDBSG.cells[dddefaultis ,cur_row] := qry.findfield('DEFAULT').text;
- fDBSG.cells[ddeditmaskis ,cur_row] := qry.findfield('EDITMASK').text;
- fDBSG.cells[ddminval ,cur_row] := qry.findfield('MINVAL').asString;
- fDBSG.cells[ddmaxval ,cur_row] := qry.findfield('MAXVAL').asString;
- fDBSG.cells[ddvallist ,cur_row] := qry.findfield('VALLIST').text;
- fDBSG.cells[ddhinttxt ,cur_row] := qry.findfield('HINT').text;
- fDBSG.cells[ddhelpid ,cur_row] := qry.findfield('HELPID').asSTring;
- fDBSG.cells[ddhaslink ,cur_row] := qry.findfield('HASLINK').asSTring;
- fDBSG.cells[ddsrclinktbl ,cur_row] := qry.findfield('SRCLINKTBL').text;
- fDBSG.cells[ddsrclinkfld ,cur_row] := qry.findfield('SRCLINKFLD').text;
- fDBSG.cells[ddiscalc ,cur_row] := qry.findfield('IS_CALC').asString;
- fDBSG.cells[ddformula ,cur_row] := qry.findfield('FORMULA').text;
- tfield }
- **)
-
- end;
- end;
-
- function TDDCtrl.SetUpBeforeString(var TableToDefine : ttable; const cur_row : integer): boolean;
- var whichfield : string;
- begin with fDBSG do begin
- whichfield := cells[ddfieldname, cur_row];
- { if cells[ddfldlen, cur_row] <> ''
- then TableToDefine.findField(whichField).size := StrToint(cells[ddfldlen, cur_row]);
- }
- end;
- end;
-
- function TDDCtrl.SetUpBeforeBoolean(var TableToDefine : ttable; const cur_row : integer): boolean;
- var whichfield : string;
- begin with fDBSG do begin
- whichfield := cells[ddfieldname, cur_row];
- { if cells[ddValList, cur_row] <> ''
- then TBooleanField(TableToDefine.findField(whichfield)).DisplayValues
- := cells[ddValList, cur_row];
- }
- end;
- end;
-
- function TDDCtrl.dobeforeNumbers(const whichtype : char; var TableToDefine : ttable; const cur_row : integer): boolean;
- var whichfield : string;
- begin with fDBSG do begin
- whichfield := cells[ddfieldname, cur_row];
- if (cells[ddminval, cur_row] = '') and (cells[ddmaxval, cur_row] = '')
- then begin
- result := true;
- exit;
- end;
- (**
- case whichtype of
- 'I': begin {ftSmallint}
- if cells[ddminval, cur_row] <> ''
- then TSmallIntField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TSmallIntField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- end;
- 'N': begin {ftInteger}
- if cells[ddminval, cur_row] <> ''
- then TIntegerField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TIntegerField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- end;
-
- 'W' : begin {ftWord}
- if cells[ddminval, cur_row] <> ''
- then TWordField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TWordField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- end;
- 'F' : begin {ftFloat}
- if cells[ddminval, cur_row] <> ''
- then TFloatField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TFloatField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- if cells[ddfldlen, cur_row] <> ''
- then TFloatField(TableToDefine.findField(whichfield)).Precision
- := StrToInt(cells[ddfldlen, cur_row]);
- end;
- 'C' : begin {ftCurrency}
- if cells[ddminval, cur_row] <> ''
- then TCurrencyField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TCurrencyField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- if cells[ddfldlen, cur_row] <> ''
- then TCurrencyField(TableToDefine.findField(whichfield)).Precision
- := StrToInt(cells[ddfldlen, cur_row]);
- end;
- 'B' : begin {ftBCD}
- if cells[ddminval, cur_row] <> ''
- then TBCDField(TableToDefine.findField(whichField)).minvalue
- := StrToInt(cells[ddMinVal, cur_row]);
- if cells[ddmaxval, cur_row] <> ''
- then TBCDField(TableToDefine.findField(whichField)).maxvalue
- := StrToInt(cells[ddMaxVal, cur_row]);
- if cells[ddfldlen, cur_row] <> ''
- then TBCDField(TableToDefine.findField(whichfield)).Precision
- := StrToInt(cells[ddfldlen, cur_row]);
- end;
- end; {Case }
- **)
- end; {with fDBSG}
- end;
-
- function TDDCtrl.setBeforeFieldDef(var tableToDefine : Ttable; const cur_row : integer): boolean;
- var temprslt : boolean;
- begin
- result := false;
- temprslt := SetUpbeforeCommon(tableToDefine, cur_row);
- case fDBSG.cells[ddfldtype,cur_row][1] of
- 'S' : {ftString} Result := SetUpbeforeString(tableToDefine, cur_row);
- 'I', {ftSmallint}
- 'N', {ftInteger}
- 'W' : {ftWord} Result := DoBeforeNumbers(fDBSG.cells[ddfldtype, cur_row][1], tableToDefine, cur_row);
- 'L' : {ftBoolean} Result := SetUpBeforeBoolean(tableToDefine, cur_row);
- 'F', {ftFloat}
- 'C', {ftCurrency}
- 'B' : {ftBCD} Result := DoBeforeNumbers(fDBSG.cells[ddfldtype, cur_row][1], tableToDefine, cur_row);
- 'D' : {ftDate} Result := SetUpDate(tableToDefine, cur_row);
- 'T' : {ftTime} Result := SetUpTime(tableToDefine, cur_row);
- 'A' : {ftDateTime} Result := SetUpDateTime(tableToDefine, cur_row);
- 'Y' : {ftBytes} Result := SetUpBytes(tableToDefine, cur_row);
- 'V' : {ftVarBytes} Result := SetUpVarBytes(tableToDefine, cur_row);
- 'O' : {ftBlob} Result := SetUpBlob(tableToDefine, cur_row);
- 'M' : {ftMemo} Result := SetUpMemo(tableToDefine, cur_row);
- 'G' : {ftGraphic} Result := SetUpGraphic(tableToDefine, cur_row);
- end; {Case & for}
- result := result and temprslt;
- end;
-
-
- function TDDCtrl.SetUpTableBeforeOpen(var TableToSetUp : ttable; const whichTable : string): boolean;
- var grid_row,
- num_ok,
- num_bad : integer;
- foundit : boolean;
- begin
- result := false;
- num_ok := 0; num_bad := 0;
- if not tableInDBSG(whichtable)
- then exit;
- with fDBSG do begin
- for grid_row := 0 to rowCount -1 do
- if cells[ddTablename, grid_row] = whichtable
- then if setBeforeFieldDef( TableToSetUp, grid_row)
- then inc(num_ok)
- else inc(num_bad);
- if num_bad = 0
- then result := true;
- end; {with fDBSG}
- end;
-
-
- {
- TIntegerField Whole numbers in the range -2,147,483,648 to 2,147,483,647
- TWordField Whole numbers in the range 0 to 65535
- TBooleanField True or False values
- TFloatField Real numbers with absolute magnitudes from 5.0*10-324 to 1.7*10308
- accurate to 15-16 digits
- TCurrencyField Currency values. The range and accuracy is the same as TFloatField
- TBCDField Real numbers with a fixed number of digits after the decimal point.
- Accurate to 18 digits. Range depends on the number of digits after the
- decimal point. [Paradox only]
- TDateField Date value
- TTimeField Time value
- TDateTimeField Date and time value
- TBytesField Arbitrary data field without a size limit
- TVarBytesField Arbitrary data field up to 65535 characters, with the actual length stored
- in the first two bytes
- TBlobField Arbitrary data field without a size limit
- TMemoField Arbitrary length text
- TGraphicField Arbitrary length graphic, such as a bitmap
- }
-
-
- procedure Register;
- begin
- RegisterComponents('Synature', [TDDCtrl]);
- end;
-
- Initialization
-
- DDctrlIsInit := false;
-
- end.
-
-